﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;

namespace TowerDefense
{
    public static class Library
    {
        public static float FindAngle(Vector2 from, Vector2 to)
        {
            double dx = to.X - from.X;
            double dy = to.Y - from.Y;
            if (dx < 0)
                return (float)(Math.Atan(dy / dx) + Math.PI);
            return (float)((Math.Atan(dy / dx)));
        }

        public static Vector2 MoveDirection(Vector2 currentPosition, double speed, float direction) 
        {
            Vector2 newPosition = new Vector2();
            newPosition.X += ((float)speed * (float)Math.Cos(direction));
            newPosition.Y += ((float)speed * (float)Math.Sin(direction));
            return newPosition;
        }

        public static float FindRange(Vector2 from, Vector2 to)
        {
            float dx = from.X > to.X ? from.X - to.X : to.X - from.X;
            float dy = from.Y > to.Y ? from.Y - to.Y : to.Y - from.Y;
            return (float)Math.Sqrt(Math.Pow(dx, 2) + Math.Pow(dy, 2));
        }
    }
}
